package history.double_exam;

// 5763. 哪种连续子字符串更长
public class LeetCode_5763 {
    public static void main(String[] args) {
        checkZeroOnes("1101");
    }
    public static boolean checkZeroOnes(String s) {
        if (s == null || s.length() == 0) return false;
        if (s.length() == 1) return s.charAt(0)=='1'?true:false;
        char [] charArray = s.toCharArray();
        int zeroMax = 0, oneMax = 0;
        boolean zero = s.charAt(0)=='1'?false:true;
        int count = 0;
        int i = 0;
        while (i < charArray.length) {
            if (zero && charArray[i] == '0') {
                i++;
                count++;
                zeroMax = Math.max(zeroMax, count);
            } else if (zero && charArray[i] != '0') {
                count=0;
                zero = false;
            } else if (!zero && charArray[i] == '1') {
                i++;
                count++;
                oneMax = Math.max(oneMax, count);
            } else if (!zero && charArray[i] != '1') {
                count=0;
                zero=true;
            }
        }
        return  oneMax > zeroMax;
    }
}
